package com.zhz.company.config.mybtatis.type;

import com.zhz.common.utils.NumberUtils;
import org.apache.ibatis.type.BigDecimalTypeHandler;

import java.math.BigDecimal;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * StrippedBigDecimalTypeHandler
 * <p>
 * 清理掉 BigDecimal 末尾多余的 0
 *
 * @author zhouhengzhe
 */
public class StrippedBigDecimalTypeHandler extends BigDecimalTypeHandler {


    @Override
    public BigDecimal getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        return NumberUtils.clearZero(super.getNullableResult(rs, columnIndex));
    }


    @Override
    public BigDecimal getNullableResult(ResultSet rs, String columnName) throws SQLException {
        return NumberUtils.clearZero(super.getNullableResult(rs, columnName));
    }


    @Override
    public BigDecimal getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return NumberUtils.clearZero(super.getNullableResult(cs, columnIndex));
    }

}
